package org.example.wx_springboot.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.example.wx_springboot.controller.request.BaseRequest;
import org.example.wx_springboot.entity.Commodity;
import org.example.wx_springboot.mapper.CommodityMapper;
import org.example.wx_springboot.service.ICommodityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.awt.print.Book;
import java.util.List;

@Service
@Slf4j
public class CommodityService implements ICommodityService {


    @Autowired
    CommodityMapper commodityMapper;

    @Override
    public List<Commodity> list() {
//        log.info("CommodityService list");
        return commodityMapper.list();
    }

    @Override
    public void save(Commodity commodity) {
        commodityMapper.seve(commodity);
    }

    @Override
    public PageInfo<Commodity> page(BaseRequest baseRequest) {
        PageHelper.startPage(baseRequest.getPageNum(), baseRequest.getPageSize());
        List<Commodity> commodity = commodityMapper.listCommodity(baseRequest);
        return new PageInfo<>(commodity);
    }

    @Override
    public Commodity getById(Integer id) {
        return commodityMapper.getById(id);
    }


}
